<?php

/**
 * App
 *
 * @package App
 * @subpackage page
 */
require_once 'App.php';

/**
 * ログイン
 *
 * <pre>ログインページ
 * </pre>
 * @package     App
 * @subpackage  page
 * @author      $Author: moriwaki $
 * @version     $Id: index.php　2008-09-10 moriwaki　$
 */
class Login_Index extends App_Page
{

    /**
     * ログインパラメーター
     *
     * @var array
     */
    var $param = null;
    
    /**
     * リソース名
     *
     * @var string
     */
    var $resource = null;
    
    /**
     * location url
     *
     * @var string
     */
    var $location_url = null;
    
    /**
     * location ng url
     *
     * @var string
     */
    var $location_ng_url = null;
    
    /**
     * onInit
     *
     * @param array $args queryString
     * @return void
     * @author moriwaki
     */
    function onInit($args)
    { 
        p('onInit');
    }
    
    /**
     * PC認証
     *
     * @return void
     * @author moriwaki
     */
    public function onClickPc()
    {
        p('onClickPC');
        p($_POST);
        $this->params = array();
        $this->params['mode'] = 'login';
        $this->params['login_id'] = trim($_POST['login_id']);
        $this->params['login_pass'] = trim($_POST['login_pass']);
        $this->resource = 'user/profile';
        $this->location_url = '/';
        $this->location_ng_url = '/register/';
    }
    
    /**
     * TOOL認証
     *
     * @return void
     * @author moriwaki
     */
    public function onClickTool()
    {
        p('onClickTOOL');
        $this->params = array();
        $this->params['mode'] = 'login';
        $this->params['admin_id'] = trim($_POST['login_id']);
        $this->params['admin_pass'] = trim($_POST['login_pass']);
        $this->resource = 'admin_auth';
        $this->location_url = '/admin/';
        $this->location_ng_url = '/admin/';
    }
    
    /**
     * モバイル認証
     *
     * @return void
     * @author moriwaki
     */
    public function onClickMobile()
    {
        p('onClickMobile');
        $this->params = array();
        $this->params['mode'] = 'device_serial';
        $this->params['device_serial'] = $device_serial;
        $this->resource = 'user/profile';
        $this->location_url = '/';
        $this->location_ng_url = '/register/';
    }
    
    /**
     * onOutput
     *
     * @return void
     * @author moriwaki
     */
    public function onOutput()
    {
        p('onOutput');
        /* ユーザ情報取得 */
        $resource = new BEAR_Resource($this->resource);
        $resource->read($this->params);
        $view = $resource->getResult();

        if (isset($view['id'])){
            /* メンバーなら */
            /* セッションに保存 */
            $user = array();
			if ($this->resource == 'admin_auth') {
				$user['is_admin_login'] = true;
			}else{
            	$user['is_login'] = true;
			}
            $user['user'] = $view;
            BEAR_Session::set('user', $user);
            BEAR_Page::redirect($this->location_url);
        }else{
            /* メンバーでなければ */
            BEAR_Page::redirect($this->location_ng_url);
        }
    }
}

new BEAR_Main('Login_Index');